Skip to content

fix(security): remove allow-same-origin from MCP Apps sandbox iframes#1064

Merged
zeroasterisk merged 4 commits intogoogle:mainfrom
zeroasterisk:fix/mcp-apps-sandbox-security
Apr 14, 2026
Merged

fix(security): remove allow-same-origin from MCP Apps sandbox iframes#1064
zeroasterisk merged 4 commits intogoogle:mainfrom
zeroasterisk:fix/mcp-apps-sandbox-security

Conversation

@zeroasterisk
Copy link
Copy Markdown
Collaborator

@zeroasterisk zeroasterisk commented Apr 3, 2026

Summary

This PR updates the iframe sandbox settings for MCP Apps to align with the MCP Apps specification and the A2UI security guide, addressing concerns about over-restriction while ensuring proper isolation. Found during review of PR #1062.

Details of Changes

1. Outer Iframe (Sandbox Proxy)

  • Change: Added sandbox="allow-scripts allow-same-origin" to the outer iframe in mcp-apps-component.ts.
  • Rationale: The MCP Apps specification (Section: Sandbox proxy) explicitly mandates that if the host is a web page, the Sandbox Proxy MUST have allow-scripts and allow-same-origin permissions. The previous draft removed the sandbox attribute entirely based on the A2UI guide's advice to not sandbox the proxy, but this update restores it to strictly comply with the spec.

2. Inner Iframe (View)

  • Change: Removed allow-same-origin from the inner iframe's sandbox settings in both mcp-apps-component.ts and sandbox.ts.
  • Change: Retained (and added where missing) allow-forms, allow-popups, and allow-modals flags.
  • Rationale: Removing allow-same-origin ensures proper isolation of untrusted content (preventing it from accessing the parent origin). Retaining the other functional flags ensures that apps can still handle forms and popups, avoiding breaking basic functionality as flagged by reviewers. This fits the spec's requirement for "restricted permissions" and follows the A2UI guide's allowed list.

Verification Results

  • The changes ensure that the outer iframe complies with the MCP spec.
  • The inner iframe is securely isolated without allow-same-origin but retains necessary UI capabilities.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request restricts the sandbox permissions for MCP app iframes by removing several flags, including allow-same-origin, to improve security. Feedback suggests that while removing allow-same-origin is appropriate, other functional flags such as allow-forms, allow-popups, and allow-modals should be retained to ensure basic application features like form submissions and popups continue to work.

The Lit sample and shared sandbox proxy included allow-same-origin in
iframe sandbox attributes, violating the MCP Apps guide/spec:

- Lit outer iframe: removed sandbox attribute entirely (guide says
  don't sandbox the proxy iframe)
- Lit sendSandboxResourceReady: allow-scripts only (was allow-scripts
  allow-forms allow-popups allow-modals allow-same-origin)
- Shared sandbox.ts inner iframe default: allow-scripts only (was
  allow-scripts allow-same-origin allow-forms)

The Angular sample already correctly used sandbox: 'allow-scripts'.

Confirmed against MCP Apps spec (SEP-1865) and AppBridge SDK docs.

Fixes security discrepancy found by Gemini Code Assist review on google#1062.
@zeroasterisk zeroasterisk force-pushed the fix/mcp-apps-sandbox-security branch from 508231a to 7fedb1b Compare April 5, 2026 03:37
@zeroasterisk zeroasterisk requested a review from dmandar April 7, 2026 01:46
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the demos continue working fine, let's do it!

(Have you tried this with a deployed version of the app? localhost is often very lax for all these sandboxing options)

const inner = document.createElement("iframe");
inner.style.cssText = "width:100%; height:100%; border:none;";
inner.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
inner.setAttribute("sandbox", "allow-scripts allow-forms allow-popups allow-modals");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is adding "allow-popups" and "allow-modals" without it being documented in the change. Is this intended?

(This is making the allowlist the same as the custom-components-example above so I'm guessing "yes".)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional, but I cannot guarantee those intentions :)

@zeroasterisk zeroasterisk merged commit b73eb45 into google:main Apr 14, 2026
9 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in A2UI Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants